package com.yjc.springcloud.alibaba.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.yjc.springcloud.alibaba.myhandler.CustomerBlockHandler;
import com.yjc.springcloud.bean.CommotResult;
import com.yjc.springcloud.bean.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shkstart
 * @create 2022-08-16 10:05
 */
@RestController
@Slf4j
public class RateLimitController {

    @GetMapping("/byResource")
    @SentinelResource(value = "byResource", blockHandlerClass = CustomerBlockHandler.class, blockHandler = "blockHandler1")
    public CommotResult byResource() {
        return new CommotResult(200, "按资源名进行限流测试", new Payment(2022L, "serial001"));
    }

//    public CommotResult blockHandler(BlockException blockException) {
//        return new CommotResult(444, blockException.getClass().getCanonicalName() + "\t 服务不可用");
//    }
}
